(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

cond1(true, x, y) → cond2(gr(x, y), x, y)
cond2(true, x, y) → cond3(gr(x, 0), x, y)
cond2(false, x, y) → cond4(gr(y, 0), x, y)
cond3(true, x, y) → cond3(gr(x, 0), p(x), y)
cond3(false, x, y) → cond1(and(gr(x, 0), gr(y, 0)), x, y)
cond4(true, x, y) → cond4(gr(y, 0), x, p(y))
cond4(false, x, y) → cond1(and(gr(x, 0), gr(y, 0)), x, y)
gr(0, x) → false
gr(s(x), 0) → true
gr(s(x), s(y)) → gr(x, y)
and(true, true) → true
and(false, x) → false
and(x, false) → false
p(0) → 0
p(s(x)) → x

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

cond1(true, x, y) → cond2(gr(x, y), x, y) [1]
cond2(true, x, y) → cond3(gr(x, 0), x, y) [1]
cond2(false, x, y) → cond4(gr(y, 0), x, y) [1]
cond3(true, x, y) → cond3(gr(x, 0), p(x), y) [1]
cond3(false, x, y) → cond1(and(gr(x, 0), gr(y, 0)), x, y) [1]
cond4(true, x, y) → cond4(gr(y, 0), x, p(y)) [1]
cond4(false, x, y) → cond1(and(gr(x, 0), gr(y, 0)), x, y) [1]
gr(0, x) → false [1]
gr(s(x), 0) → true [1]
gr(s(x), s(y)) → gr(x, y) [1]
and(true, true) → true [1]
and(false, x) → false [1]
and(x, false) → false [1]
p(0) → 0 [1]
p(s(x)) → x [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

cond1(true, x, y) → cond2(gr(x, y), x, y) [1]
cond2(true, x, y) → cond3(gr(x, 0), x, y) [1]
cond2(false, x, y) → cond4(gr(y, 0), x, y) [1]
cond3(true, x, y) → cond3(gr(x, 0), p(x), y) [1]
cond3(false, x, y) → cond1(and(gr(x, 0), gr(y, 0)), x, y) [1]
cond4(true, x, y) → cond4(gr(y, 0), x, p(y)) [1]
cond4(false, x, y) → cond1(and(gr(x, 0), gr(y, 0)), x, y) [1]
gr(0, x) → false [1]
gr(s(x), 0) → true [1]
gr(s(x), s(y)) → gr(x, y) [1]
and(true, true) → true [1]
and(false, x) → false [1]
and(x, false) → false [1]
p(0) → 0 [1]
p(s(x)) → x [1]

The TRS has the following type information:
cond1 :: true:false → 0:s → 0:s → cond1:cond2:cond3:cond4
true :: true:false
cond2 :: true:false → 0:s → 0:s → cond1:cond2:cond3:cond4
gr :: 0:s → 0:s → true:false
cond3 :: true:false → 0:s → 0:s → cond1:cond2:cond3:cond4
0 :: 0:s
false :: true:false
cond4 :: true:false → 0:s → 0:s → cond1:cond2:cond3:cond4
p :: 0:s → 0:s
and :: true:false → true:false → true:false
s :: 0:s → 0:s

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:

cond1(v0, v1, v2) → null_cond1 [0]

And the following fresh constants:

null_cond1

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

cond1(true, x, y) → cond2(gr(x, y), x, y) [1]
cond2(true, x, y) → cond3(gr(x, 0), x, y) [1]
cond2(false, x, y) → cond4(gr(y, 0), x, y) [1]
cond3(true, x, y) → cond3(gr(x, 0), p(x), y) [1]
cond3(false, x, y) → cond1(and(gr(x, 0), gr(y, 0)), x, y) [1]
cond4(true, x, y) → cond4(gr(y, 0), x, p(y)) [1]
cond4(false, x, y) → cond1(and(gr(x, 0), gr(y, 0)), x, y) [1]
gr(0, x) → false [1]
gr(s(x), 0) → true [1]
gr(s(x), s(y)) → gr(x, y) [1]
and(true, true) → true [1]
and(false, x) → false [1]
and(x, false) → false [1]
p(0) → 0 [1]
p(s(x)) → x [1]
cond1(v0, v1, v2) → null_cond1 [0]

The TRS has the following type information:
cond1 :: true:false → 0:s → 0:s → null_cond1
true :: true:false
cond2 :: true:false → 0:s → 0:s → null_cond1
gr :: 0:s → 0:s → true:false
cond3 :: true:false → 0:s → 0:s → null_cond1
0 :: 0:s
false :: true:false
cond4 :: true:false → 0:s → 0:s → null_cond1
p :: 0:s → 0:s
and :: true:false → true:false → true:false
s :: 0:s → 0:s
null_cond1 :: null_cond1

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

true => 1
0 => 0
false => 0
null_cond1 => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

and(z, z') -{ 1 }→ 1 :|: z = 1, z' = 1
and(z, z') -{ 1 }→ 0 :|: z' = x, x >= 0, z = 0
and(z, z') -{ 1 }→ 0 :|: x >= 0, z = x, z' = 0
cond1(z, z', z'') -{ 1 }→ cond2(gr(x, y), x, y) :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
cond1(z, z', z'') -{ 0 }→ 0 :|: v0 >= 0, z'' = v2, v1 >= 0, z = v0, z' = v1, v2 >= 0
cond2(z, z', z'') -{ 1 }→ cond4(gr(y, 0), x, y) :|: z' = x, z'' = y, x >= 0, y >= 0, z = 0
cond2(z, z', z'') -{ 1 }→ cond3(gr(x, 0), x, y) :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
cond3(z, z', z'') -{ 1 }→ cond3(gr(x, 0), p(x), y) :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
cond3(z, z', z'') -{ 1 }→ cond1(and(gr(x, 0), gr(y, 0)), x, y) :|: z' = x, z'' = y, x >= 0, y >= 0, z = 0
cond4(z, z', z'') -{ 1 }→ cond4(gr(y, 0), x, p(y)) :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
cond4(z, z', z'') -{ 1 }→ cond1(and(gr(x, 0), gr(y, 0)), x, y) :|: z' = x, z'' = y, x >= 0, y >= 0, z = 0
gr(z, z') -{ 1 }→ gr(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
gr(z, z') -{ 1 }→ 1 :|: x >= 0, z = 1 + x, z' = 0
gr(z, z') -{ 1 }→ 0 :|: z' = x, x >= 0, z = 0
p(z) -{ 1 }→ x :|: x >= 0, z = 1 + x
p(z) -{ 1 }→ 0 :|: z = 0

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1, V2),0,[cond1(V, V1, V2, Out)],[V >= 0,V1 >= 0,V2 >= 0]).
eq(start(V, V1, V2),0,[cond2(V, V1, V2, Out)],[V >= 0,V1 >= 0,V2 >= 0]).
eq(start(V, V1, V2),0,[cond3(V, V1, V2, Out)],[V >= 0,V1 >= 0,V2 >= 0]).
eq(start(V, V1, V2),0,[cond4(V, V1, V2, Out)],[V >= 0,V1 >= 0,V2 >= 0]).
eq(start(V, V1, V2),0,[gr(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V2),0,[and(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V2),0,[p(V, Out)],[V >= 0]).
eq(cond1(V, V1, V2, Out),1,[gr(V3, V4, Ret0),cond2(Ret0, V3, V4, Ret)],[Out = Ret,V1 = V3,V2 = V4,V = 1,V3 >= 0,V4 >= 0]).
eq(cond2(V, V1, V2, Out),1,[gr(V5, 0, Ret01),cond3(Ret01, V5, V6, Ret1)],[Out = Ret1,V1 = V5,V2 = V6,V = 1,V5 >= 0,V6 >= 0]).
eq(cond2(V, V1, V2, Out),1,[gr(V7, 0, Ret02),cond4(Ret02, V8, V7, Ret2)],[Out = Ret2,V1 = V8,V2 = V7,V8 >= 0,V7 >= 0,V = 0]).
eq(cond3(V, V1, V2, Out),1,[gr(V9, 0, Ret03),p(V9, Ret11),cond3(Ret03, Ret11, V10, Ret3)],[Out = Ret3,V1 = V9,V2 = V10,V = 1,V9 >= 0,V10 >= 0]).
eq(cond3(V, V1, V2, Out),1,[gr(V11, 0, Ret00),gr(V12, 0, Ret011),and(Ret00, Ret011, Ret04),cond1(Ret04, V11, V12, Ret4)],[Out = Ret4,V1 = V11,V2 = V12,V11 >= 0,V12 >= 0,V = 0]).
eq(cond4(V, V1, V2, Out),1,[gr(V13, 0, Ret05),p(V13, Ret21),cond4(Ret05, V14, Ret21, Ret5)],[Out = Ret5,V1 = V14,V2 = V13,V = 1,V14 >= 0,V13 >= 0]).
eq(cond4(V, V1, V2, Out),1,[gr(V15, 0, Ret001),gr(V16, 0, Ret012),and(Ret001, Ret012, Ret06),cond1(Ret06, V15, V16, Ret6)],[Out = Ret6,V1 = V15,V2 = V16,V15 >= 0,V16 >= 0,V = 0]).
eq(gr(V, V1, Out),1,[],[Out = 0,V1 = V17,V17 >= 0,V = 0]).
eq(gr(V, V1, Out),1,[],[Out = 1,V18 >= 0,V = 1 + V18,V1 = 0]).
eq(gr(V, V1, Out),1,[gr(V19, V20, Ret7)],[Out = Ret7,V1 = 1 + V20,V19 >= 0,V20 >= 0,V = 1 + V19]).
eq(and(V, V1, Out),1,[],[Out = 1,V = 1,V1 = 1]).
eq(and(V, V1, Out),1,[],[Out = 0,V1 = V21,V21 >= 0,V = 0]).
eq(and(V, V1, Out),1,[],[Out = 0,V22 >= 0,V = V22,V1 = 0]).
eq(p(V, Out),1,[],[Out = 0,V = 0]).
eq(p(V, Out),1,[],[Out = V23,V23 >= 0,V = 1 + V23]).
eq(cond1(V, V1, V2, Out),0,[],[Out = 0,V24 >= 0,V2 = V25,V26 >= 0,V = V24,V1 = V26,V25 >= 0]).
input_output_vars(cond1(V,V1,V2,Out),[V,V1,V2],[Out]).
input_output_vars(cond2(V,V1,V2,Out),[V,V1,V2],[Out]).
input_output_vars(cond3(V,V1,V2,Out),[V,V1,V2],[Out]).
input_output_vars(cond4(V,V1,V2,Out),[V,V1,V2],[Out]).
input_output_vars(gr(V,V1,Out),[V,V1],[Out]).
input_output_vars(and(V,V1,Out),[V,V1],[Out]).
input_output_vars(p(V,Out),[V],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================
3. SCC does not have a single cut point : [cond3/4,cond4/4]
Merged into cond3cond4/4

#### Computed strongly connected components
0. non_recursive : [and/3]
1. recursive : [gr/3]
2. non_recursive : [p/2]
4. non_recursive : [start/3]
3. recursive : [cond1/4,cond2/4,cond3cond4/4]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into and/3
1. SCC is partially evaluated into gr/3
2. SCC is partially evaluated into p/2
4. SCC is partially evaluated into start/3
3. SCC is partially evaluated into cond3cond4/4

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations and/3
* CE 21 is refined into CE [24]
* CE 19 is refined into CE [25]
* CE 20 is refined into CE [26]


### Cost equations --> "Loop" of and/3
* CEs [24] --> Loop 15
* CEs [25] --> Loop 16
* CEs [26] --> Loop 17

### Ranking functions of CR and(V,V1,Out)

#### Partial ranking functions of CR and(V,V1,Out)


### Specialization of cost equations gr/3
* CE 13 is refined into CE [27]
* CE 12 is refined into CE [28]
* CE 11 is refined into CE [29]


### Cost equations --> "Loop" of gr/3
* CEs [28] --> Loop 18
* CEs [29] --> Loop 19
* CEs [27] --> Loop 20

### Ranking functions of CR gr(V,V1,Out)
* RF of phase [20]: [V,V1]

#### Partial ranking functions of CR gr(V,V1,Out)
* Partial RF of phase [20]:
- RF of loop [20:1]:
V
V1


### Specialization of cost equations p/2
* CE 23 is refined into CE [30]
* CE 22 is refined into CE [31]


### Cost equations --> "Loop" of p/2
* CEs [30] --> Loop 21
* CEs [31] --> Loop 22

### Ranking functions of CR p(V,Out)

#### Partial ranking functions of CR p(V,Out)


### Specialization of cost equations cond3cond4/4
* CE 17 is refined into CE [32,33]
* CE 18 is refined into CE [34,35]
* CE 15 is refined into CE [36]
* CE 16 is refined into CE [37]
* CE 14 is refined into CE [38,39,40,41,42]


### Cost equations --> "Loop" of cond3cond4/4
* CEs [42] --> Loop 23
* CEs [41] --> Loop 24
* CEs [40] --> Loop 25
* CEs [38,39] --> Loop 26
* CEs [35] --> Loop 27
* CEs [33] --> Loop 28
* CEs [34] --> Loop 29
* CEs [32] --> Loop 30
* CEs [36] --> Loop 31
* CEs [37] --> Loop 32

### Ranking functions of CR cond3cond4(A,B,C,D)
* RF of phase [27,28]: [B+C]

#### Partial ranking functions of CR cond3cond4(A,B,C,D)
* Partial RF of phase [27,28]:
- RF of loop [27:1]:
C
- RF of loop [28:1]:
B


### Specialization of cost equations start/3
* CE 3 is refined into CE [43,44,45]
* CE 4 is refined into CE [46,47,48]
* CE 6 is refined into CE [49,50,51,52]
* CE 2 is refined into CE [53]
* CE 5 is refined into CE [54,55,56]
* CE 7 is refined into CE [57,58,59,60,61,62,63]
* CE 8 is refined into CE [64,65,66,67]
* CE 9 is refined into CE [68,69,70]
* CE 10 is refined into CE [71,72]


### Cost equations --> "Loop" of start/3
* CEs [43,44,52,63] --> Loop 33
* CEs [66,67,69,72] --> Loop 34
* CEs [45,47,48,50,51,53,62] --> Loop 35
* CEs [46,49,61,65,70] --> Loop 36
* CEs [54,55,56,57,58,59,60,64,68,71] --> Loop 37

### Ranking functions of CR start(V,V1,V2)

#### Partial ranking functions of CR start(V,V1,V2)


Computing Bounds
=====================================

#### Cost of chains of and(V,V1,Out):
* Chain [17]: 1
with precondition: [V=0,Out=0,V1>=0]

* Chain [16]: 1
with precondition: [V=1,V1=1,Out=1]

* Chain [15]: 1
with precondition: [V1=0,Out=0,V>=0]


#### Cost of chains of gr(V,V1,Out):
* Chain [[20],19]: 1*it(20)+1
Such that:it(20) =< V

with precondition: [Out=0,V>=1,V1>=V]

* Chain [[20],18]: 1*it(20)+1
Such that:it(20) =< V1

with precondition: [Out=1,V1>=1,V>=V1+1]

* Chain [19]: 1
with precondition: [V=0,Out=0,V1>=0]

* Chain [18]: 1
with precondition: [V1=0,Out=1,V>=1]


#### Cost of chains of p(V,Out):
* Chain [22]: 1
with precondition: [V=0,Out=0]

* Chain [21]: 1
with precondition: [V=Out+1,V>=1]


#### Cost of chains of cond3cond4(A,B,C,D):
* Chain [[27,28],30,26]: 3*it(27)+3*it(28)+7
Such that:it(28) =< B
it(27) =< C
aux(3) =< B+C
it(27) =< aux(3)
it(28) =< aux(3)

with precondition: [A=1,D=0,B>=0,C>=0,B+C>=1]

* Chain [[27,28],30,25]: 3*it(27)+3*it(28)+7
Such that:it(28) =< B
it(27) =< C
aux(4) =< B+C
it(27) =< aux(4)
it(28) =< aux(4)

with precondition: [A=1,D=0,B>=0,C>=1,B+C>=2]

* Chain [[27,28],29,26]: 3*it(27)+3*it(28)+7
Such that:it(28) =< B
it(27) =< C
aux(5) =< B+C
it(27) =< aux(5)
it(28) =< aux(5)

with precondition: [A=1,D=0,B>=0,C>=0,B+C>=1]

* Chain [[27,28],29,24]: 3*it(27)+3*it(28)+7
Such that:it(28) =< B
it(27) =< C
aux(6) =< B+C
it(27) =< aux(6)
it(28) =< aux(6)

with precondition: [A=1,D=0,B>=1,C>=0,B+C>=2]

* Chain [32,[27,28],30,26]: 3*it(27)+3*it(28)+1*s(1)+15
Such that:aux(3) =< B+C
it(27) =< C
aux(7) =< B
it(28) =< aux(7)
s(1) =< aux(7)
it(27) =< aux(3)
it(28) =< aux(3)

with precondition: [A=0,D=0,B>=1,C>=B]

* Chain [32,[27,28],30,25]: 3*it(27)+3*it(28)+1*s(1)+15
Such that:aux(4) =< B+C
it(27) =< C
aux(8) =< B
it(28) =< aux(8)
s(1) =< aux(8)
it(27) =< aux(4)
it(28) =< aux(4)

with precondition: [A=0,D=0,B>=1,C>=B]

* Chain [32,[27,28],29,26]: 3*it(27)+3*it(28)+1*s(1)+15
Such that:aux(5) =< B+C
it(27) =< C
aux(9) =< B
it(28) =< aux(9)
s(1) =< aux(9)
it(27) =< aux(5)
it(28) =< aux(5)

with precondition: [A=0,D=0,B>=1,C>=B]

* Chain [32,[27,28],29,24]: 3*it(27)+3*it(28)+1*s(1)+15
Such that:aux(6) =< B+C
it(27) =< C
aux(10) =< B
it(28) =< aux(10)
s(1) =< aux(10)
it(27) =< aux(6)
it(28) =< aux(6)

with precondition: [A=0,D=0,B>=1,C>=B]

* Chain [31,[27,28],30,26]: 3*it(27)+3*it(28)+1*s(2)+15
Such that:it(28) =< B
aux(3) =< B+C
aux(11) =< C
it(27) =< aux(11)
s(2) =< aux(11)
it(27) =< aux(3)
it(28) =< aux(3)

with precondition: [A=0,D=0,C>=1,B>=C+1]

* Chain [31,[27,28],30,25]: 3*it(27)+3*it(28)+1*s(2)+15
Such that:it(28) =< B
aux(4) =< B+C
aux(12) =< C
it(27) =< aux(12)
s(2) =< aux(12)
it(27) =< aux(4)
it(28) =< aux(4)

with precondition: [A=0,D=0,C>=1,B>=C+1]

* Chain [31,[27,28],29,26]: 3*it(27)+3*it(28)+1*s(2)+15
Such that:it(28) =< B
aux(5) =< B+C
aux(13) =< C
it(27) =< aux(13)
s(2) =< aux(13)
it(27) =< aux(5)
it(28) =< aux(5)

with precondition: [A=0,D=0,C>=1,B>=C+1]

* Chain [31,[27,28],29,24]: 3*it(27)+3*it(28)+1*s(2)+15
Such that:it(28) =< B
aux(6) =< B+C
aux(14) =< C
it(27) =< aux(14)
s(2) =< aux(14)
it(27) =< aux(6)
it(28) =< aux(6)

with precondition: [A=0,D=0,C>=1,B>=C+1]

* Chain [30,26]: 7
with precondition: [A=1,B=0,C=0,D=0]

* Chain [30,25]: 7
with precondition: [A=1,B=0,D=0,C>=1]

* Chain [29,26]: 7
with precondition: [A=1,B=0,C=0,D=0]

* Chain [29,24]: 7
with precondition: [A=1,C=0,D=0,B>=1]

* Chain [26]: 4
with precondition: [A=0,B=0,C=0,D=0]

* Chain [25]: 4
with precondition: [A=0,B=0,D=0,C>=1]

* Chain [24]: 4
with precondition: [A=0,C=0,D=0,B>=1]

* Chain [23]: 4
with precondition: [A=0,D=0,B>=1,C>=1]


#### Cost of chains of start(V,V1,V2):
* Chain [37]: 36*s(58)+36*s(59)+4*s(65)+4*s(66)+15
Such that:aux(21) =< V1
aux(22) =< V1+V2
aux(23) =< V2
s(58) =< aux(21)
s(59) =< aux(23)
s(59) =< aux(22)
s(58) =< aux(22)
s(65) =< aux(23)
s(66) =< aux(21)

with precondition: [V=0]

* Chain [36]: 8
with precondition: [V1=0,V>=0]

* Chain [35]: 13*s(67)+48*s(71)+48*s(72)+1*s(78)+11
Such that:aux(27) =< V1
aux(28) =< V1+V2
aux(29) =< V2
s(67) =< aux(29)
s(71) =< aux(27)
s(72) =< aux(29)
s(72) =< aux(28)
s(71) =< aux(28)
s(78) =< aux(27)

with precondition: [V>=0,V1>=0,V2>=0]

* Chain [34]: 1*s(94)+1*s(95)+1
Such that:s(94) =< V
s(95) =< V1

with precondition: [V>=1]

* Chain [33]: 12*s(99)+11
Such that:aux(30) =< V1
s(99) =< aux(30)

with precondition: [V=1,V2=0,V1>=1]


Closed-form bounds of start(V,V1,V2):
-------------------------------------
* Chain [37] with precondition: [V=0]
- Upper bound: nat(V1)*40+15+nat(V2)*40
- Complexity: n
* Chain [36] with precondition: [V1=0,V>=0]
- Upper bound: 8
- Complexity: constant
* Chain [35] with precondition: [V>=0,V1>=0,V2>=0]
- Upper bound: 49*V1+61*V2+11
- Complexity: n
* Chain [34] with precondition: [V>=1]
- Upper bound: V+1+nat(V1)
- Complexity: n
* Chain [33] with precondition: [V=1,V2=0,V1>=1]
- Upper bound: 12*V1+11
- Complexity: n

### Maximum cost of start(V,V1,V2): max([7,nat(V1)+max([V,nat(V2)*40+nat(V1)*28+max([4,nat(V2)*21+nat(V1)*9])+ (nat(V1)*11+10)])])+1
Asymptotic class: n
* Total analysis performed in 631 ms.

(10) BOUNDS(1, n^1)